package com.zmj.sy.mom.srv.aps.service.scheduler.order;

import com.zmj.sy.mom.srv.aps.bean.entity.order.ApsOrder;
import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import com.zmj.sy.mom.srv.aps.bean.entity.order.ReverseOrder;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Getter
@Setter
@ApiModel(value = "订单信息")
public class DefaultOrder {

    @ApiModelProperty(value = "订单基础信息")
    private Order order;

    @ApiModelProperty(value = "订单拆包信息")
    private List<ReverseOrder> reverseOrders;

    @ApiModelProperty(value = "订单拆包信息")
    private List<ApsOrder> apsOrders;

    @ApiModelProperty(value = "订单BOM信息")
    private List<DefaultBom> bomList;

    @ApiModelProperty(value = "订单BOM工序信息")
    private List<DefaultPhase> phaseList;

    private transient List<DefaultBom> roots;

    /**
     * 获取订单的根节点
     */
    public List<DefaultBom> getRoots() {
        if (this.roots == null) {
            this.roots = bomList.stream()
                    .filter(bom -> Objects.equals(bom.getBom().getLevel(), 1))
                    .collect(Collectors.toList());
        }
        return this.roots;
    }

}
